home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / Commander Sets / 4D Speech Pack / 4D Speech Pack.rsrc / TEXT_9721_†B_ Speak Procedure.txt < prev   
Encoding:
Text File  |  1994-09-14  |  4.8 KB  |  130 lines

  1. Speak Procedure
  2.  
  3. `procedure to speak the contents of every enterable field on a layout
  4. `written by Ren√© G.A. Ros, author of Speech Pack external
  5. `date: 12 October 1993
  6. `use with Speech Pack 2.1 or later
  7. `needs 4th Dimension 2.1 or later
  8.  
  9. `syntax:
  10. `SPEAK(pointer;selector)
  11. `where:
  12. `pointer is a pointer to the object i.e. obtained by using Last Area
  13. `selector specifies the type of action undertaken
  14. `0 = non, redraw buttons only
  15. `1 = play
  16. `2 = stop
  17. `3 = pause
  18. `for the compiler put this somewhere else:
  19. `C_POINTER("SPEAK";$1)
  20. `C_INTEGER("SPEAK";$2)
  21. `(I'am I correct? I don't use the compiler and no v3 manuals available)
  22.  
  23. `this procedure assumes:
  24. `- in the startup procedure a voice was opened by using:
  25. `  C_INTEGER($err;SpeechRef)
  26. `  $err := SP Voice Open("*";SpeechRef)
  27. `- the voice will be closed properly in any quit procedure:
  28. `  $err := SP Voice Close(SpeechRef)
  29. `  (4D v3 USERS CAN MAKE SpeechRef A INTERPROCESS VARIABLE)
  30.  
  31. `the designer can call this procedure either by menu procedures or buttons.
  32. `this procedure assumes you are using at least three buttons with these names
  33. `and only one line in their script
  34. `SpeechPlay
  35. `  SPEAK(Last Area;1)
  36. `SpeechStop
  37. `  SPEAK(Last Area;2)
  38. `SpeechPause
  39. `  SPEAK(Last Area;2)
  40. `of which 'SCRIPT: Only if modified' is enabled
  41. `BTW 'Last Area' can be every other pointer ofcourse
  42. `if you want to allow only to speak a text field use a pointer to that field
  43.  
  44. `from the layout procedure you can call:
  45. `  SPEAK(Last Area;0)
  46. `to reset the button state correctly
  47. `(in this case the pointer is ignored)
  48.  
  49. C_INTEGER($err;$first;$last)
  50. C_STRING(255;$speakstring)
  51.  
  52. If (Not(Nil($1)))`if parameter is valid pointer
  53.   If (SP Can speak >0)`if we can speak do so and set buttons accordingly
  54.     Case of 
  55.       : ($2=1)`play
  56.         If (SP Voice busy (SpeechRef)=2)`if the voice is paused than this selector acts as 'continue'
  57.           $err:=SP Voice Cont (SpeechRef)`thus: continue speaking
  58.           
  59.         Else `the voice is not paused so just speak the data
  60.           If (Type($1¬ª)=2)`since a text field has its own Speech Pack command‚Ķ
  61.             GET HIGHLIGHT($1¬ª;$first;$last)`get the selection of the text
  62.             $err:=SP Voice Text (SpeechRef;$1¬ª;$first;$last;0)`and say it
  63.           Else `everything else but a text field ends here
  64.             Case of `convert the field data into a string based on the data type
  65.               : (Type($1¬ª)=0)`normal string
  66.                 $speakstring:=$1¬ª`just copy it
  67.               : (Type($1¬ª)=1)`real
  68.                 $speakstring:=String($1¬ª)`convert using String
  69.               : (Type($1¬ª)=4)`date
  70.                 $speakstring:=String($1¬ª;3)`convert using String with the long format
  71.               : (Type($1¬ª)=6)`boolean
  72.                 $speakstring:=("true"*Num($1¬ª))+("false"*Num(Not($1¬ª)))`difficult what to say, simple TRUE or FALSE I guess
  73.               : (Type($1¬ª)=8)`integer
  74.                 $speakstring:=String($1¬ª)`convert using String
  75.               : (Type($1¬ª)=9)`long int
  76.                 $speakstring:=String($1¬ª)`convert using String
  77.               : (Type($1¬ª)=11)`time
  78.                 $speakstring:=String($1¬ª;5)`convert using String with the hh:mm AM/PM format
  79.               Else 
  80.                 $speakstring:=""`anything else gives an empty string
  81.             End case 
  82.             
  83.             If ($speakstring#"")`if empty don't try it, interrupt previous speaking
  84.               $err:=SP Voice String (SpeechRef;$speakstring)`say it!
  85.             End if 
  86.             
  87.           End if 
  88.           
  89.         End if 
  90.         
  91.         `much simpler now: (we're are still in the case statement for the selector!)
  92.       : ($2=2)`stop
  93.         $err:=SP Voice Stop (SpeechRef)`stop the voice (testing if busy is done by external)
  94.       : ($2=3)`pause
  95.         $err:=SP Voice Pause (SpeechRef)`pause the voice (testing if busy is done by external)
  96.     End case 
  97.     
  98.     `now set the buttons
  99.     $status:=SP Voice busy (SpeechRef)`the others depend on the state of speaking
  100.     Case of 
  101.       : ($status=0)`idle
  102.         ENABLE BUTTON(SpeechPlay)`play is always enabled 
  103.         DISABLE BUTTON(SpeechStop)`the voice is not active so disabled
  104.         DISABLE BUTTON(SpeechPause)
  105.       : ($status=1)`busy
  106.         ENABLE BUTTON(SpeechPlay)`play is always enabled 
  107.         ENABLE BUTTON(SpeechStop)`user can either stop‚Ķ
  108.         ENABLE BUTTON(SpeechPause)`or pause
  109.       : ($status=2)`paused
  110.         ENABLE BUTTON(SpeechPlay)`play is always enabled 
  111.         ENABLE BUTTON(SpeechStop)`user can stop but‚Ķ
  112.         DISABLE BUTTON(SpeechPause)`voice paused already
  113.       Else 
  114.         DISABLE BUTTON(SpeechPlay)`the voice is not active so disable all
  115.         DISABLE BUTTON(SpeechStop)
  116.         DISABLE BUTTON(SpeechPause)
  117.     End case 
  118.     
  119.   Else 
  120.     
  121.     DISABLE BUTTON(SpeechPlay)`can't speak so disable buttons
  122.     DISABLE BUTTON(SpeechStop)
  123.     DISABLE BUTTON(SpeechPause)
  124.     
  125.   End if 
  126. End if 
  127.  
  128.  
  129.  
  130.